<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>供应商列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<script type="text/javascript">
	var grid = null;
	var _mfrId;
	var pageInApp={}; // to 下一级子窗口 接口
    var pageInTab=null;
	$(function () {
		_atcId = '${id}';
		var _url = '<%=path%>/product/splInfo/initList.do?atcId=' + _atcId ;
	    $("#ligergrid1").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
	            { display: '供应商名称', align:'left', width: 200,
	            	render: function (rowdata, rowindex, value){
	            		var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.id+"'";
		                if(StringUtils.isNotEmpty(rowdata.splAttrCd)){
			                h+=",'"+rowdata.splAttrCd+"'";
		                }else{
			                h+=",''";
		                }
	                    h+=')">'+rowdata.splNm+'</a>';
	                	return h;
	            	}	
	            },
	            { display: '供应商属性', name: 'splAttrCd',width: 60 ,
	            	render: function (rowdata, rowindex, value){
	            		if(StringUtils.isNotEmpty(value) && value==CustomerConstant.CST_TYPE_NP_CD){//1自然人 2法人
	            			return "自然人";
	            		}else{
	            			return "法人";
	            		}
	                }
	            },
	            { display: '营业执照号/证件号', name: 'bizLicNo', align:'left', width: 150 },
	            /*{ display: '税务登记号', name: 'taxRegNo', align:'left', width: 150 },
	            { display: '组织机构代码号', name: 'orgCode', align:'left', width: 150 },
	            */
	            { display: '所属机构', name: 'buOrgCdNms', align:'left', width: 200 ,isEllipsis: false,
	            	render: function (rowdata, rowindex, value){
	            		if(StringUtils.isEmpty(value)){
	            			return "";
	            		}else{
		                    var h='<span class="gridTip" title="'+ value +'">'+ value +'</span>'
		                    return h;
	            		}
	                }
	            },
	            //{ display: '实际控制人', name: 'rlNm', width: 100 }, 
	            //{ display: '联系方式', name: 'tel', width: 100},
	            { display: '审核状态', width: 80, 
	            	render: function (rowdata, rowindex, value){
	            		if(rowdata && rowdata.sysFlowSHDTOList && rowdata.sysFlowSHDTOList.length==1){
	            			var audStsCd = rowdata.sysFlowSHDTOList[0].audStsCd;
	            			if(StringUtils.isNotEmpty(audStsCd)){
	            				if(audStsCd == '1'){
			            			return '审核中';
	            				}else if(audStsCd == '2'){
			            			return '审核通过';
	            				}else if(audStsCd == '3'){
			            			return '审核不通过';
	            				}else if(audStsCd == '4'){
			            			return '驳回呈报人';
	            				}
	            			}
	            		}else if(!rowdata.sysFlowSHDTOList || rowdata.sysFlowSHDTOList.length==0){
	            			return '待提交';
	            		}
	            	}
	            },
				{ display: '流程编号', minWidth: 220,isEllipsis: false,
					render: function (rowdata, rowindex, value){
						if(rowdata && rowdata.sysFlowSHDTOList && rowdata.sysFlowSHDTOList.length==1){
	            			var pno = rowdata.sysFlowSHDTOList[0].pno;
	            			var audStsCd = rowdata.sysFlowSHDTOList[0].audStsCd;
	            			var pinstId = rowdata.sysFlowSHDTOList[0].pinstId;
	            			var dataId = rowdata.sysFlowSHDTOList[0].dataId;
	            			if(StringUtils.isNotEmpty(pinstId)
	            					&& StringUtils.isNotEmpty(audStsCd)
	            					&& StringUtils.isNotEmpty(dataId)
	            					&& StringUtils.isNotEmpty(pno)){
	            				var h='<a href="javascript:showFlow(';
								h+="'"+pinstId+"'";
								h+=",'"+audStsCd+"'";
								h+=",'"+dataId+"'";
								h+=')">'+pno+'</a>';
	            				return h;
	            			}
	            		}else if(rowdata && rowdata.sysFlowSHDTOList && rowdata.sysFlowSHDTOList.length>1){
	            			var h = "";
            				for(var i = 0;i < rowdata.sysFlowSHDTOList.length; i++) {
            					if(i!=0){
            						h+='</br>';
            					}
	            				var pno = rowdata.sysFlowSHDTOList[i].pno;
		            			var audStsCd = rowdata.sysFlowSHDTOList[i].audStsCd;
		            			var pinstId = rowdata.sysFlowSHDTOList[i].pinstId;
		            			var dataId = rowdata.sysFlowSHDTOList[i].dataId;
	            				h+='<a href="javascript:showFlow(';
								h+="'"+pinstId+"'";
								h+=",'"+audStsCd+"'";
								h+=",'"+dataId+"'";
								h+=')">'+pno+'</a>';
								if(audStsCd == '1'){
			            			h+= ' - 审核中 ';
	            				}else if(audStsCd == '2'){
			            			h += ' - 审核通过 ';
	            				}else if(audStsCd == '3'){
			            			h += ' - 审核不通过 ';
	            				}else if(audStsCd == '4'){
			            			h += ' - 驳回呈报人';
	            				}
	            			}
	            			return h;
	            		}
					}
				},
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        fixedCellHeight: false,
	        rownumbers:true,
//			onAfterShowData: getFlowIds,
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	});

	//2017-7-12 15:28:57  jiangzg 显示数据之后，请求获取流程编号
	function getFlowIds() {
		var h = "";
		var pinstId = "";
		var audStsCd = "";
		var dataId = "";
		var pno = "";
		var jsonDatas = [];
		g = liger.get("ligergrid1");
		var dd = g.getData();
		var jsonData = JSON.stringify(dd);
		$.ajax({
			async: false,
			type: 'post',
			dataType: 'json',
			data: {data: jsonData, busTyp: "003"},
			url: '<%=path%>/product/splInfo/getSplSHFlowInfo.do',
			success: function (msg) {
				jsonDatas = JSON.stringify(msg);
			}
		});
//        console.log(g.columns.length);
		var oriData = eval("(" + jsonData + ")");
		var dataInfo = eval("(" + jsonDatas + ")");
		for(var c = 0;c<g.columns.length;c++){
			if(g.columns[c] != null && g.columns[c].name == 'pinstNm'){
//                console.log(g.columns[c]);
				var num = c ;
				for (var i = 0; i < oriData.length; i++) {
					if (dataInfo[i].is_Flow_yesOrNo == "yes") {
						pinstId = dataInfo[i].sysFlowSHDTO.pinstId;
						audStsCd = dataInfo[i].sysFlowSHDTO.audStsCd;
						dataId = dataInfo[i].sysFlowSHDTO.dataId;
						pno = dataInfo[i].sysFlowSHDTO.pno;
						if (StringUtils.isNotEmpty(pno)) {
							h = '<a href="javascript:showFlow(';
							h += "'" + pinstId + "'";
							h += ",'" + audStsCd + "'";
							h += ",'" + dataId + "'";
							h += ')">' + pno + '</a>';
						}
						oriData[i].pinstNm = h;
					} else {
						oriData[i].pinstNm = "";
					}
					g.updateCell(num, oriData[i].pinstNm, i);
				}
				g.isDataChanged = false;
			}
			if(g.columns[c] != null && g.columns[c].name == 'audStsCdNm'){
//                console.log(g.columns[c]);
				var num = c ;
				for (var i = 0; i < oriData.length; i++) {
					if (dataInfo[i].is_Flow_yesOrNo == "yes") {
						audStsCd = dataInfo[i].sysFlowSHDTO.audStsCd;
						oriData[i].audStsCdNm = audStsCd;
						console.log("++++"+audStsCd);
					} else {
						oriData[i].audStsCdNm = "";
						console.log("------"+audStsCd);
					}
					g.updateCell(num, oriData[i].audStsCdNm, i);
				}
				g.isDataChanged = false;
			}
		}
	}

	//显示流程
	function showFlow(_pInstId,_audStsCd,_businessKey){
		if(StringUtils.isEmpty(_pInstId)){
			UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
			return;
		}
		var _formUrl = "/product/splInfo/toDetailPage.do?isFlow=1@@id=";
		var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
		Add_navTab('tab_spl_bank_flow_'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
	}

	//详情
	function showDetail(_id,_splAttrCd){
		if(!_id)return;
		if(_mfrId==""){
			parent.mainApp.f_addTab('PrdSpl_3'+_id,'供应商详情','<%=path%>/product/splInfo/toDetailPage.do?id='+_id+'&splAttrCd='+_splAttrCd);
		}else{
			parent.parent.mainApp.f_addTab('PrdSpl_3'+_id,'供应商详情','<%=path%>/product/splInfo/toDetailPage.do?id='+_id+'&splAttrCd='+_splAttrCd);
		}
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	
</script>

<body class="iframeBody">
<div class="Wrapper">
	<div id="ligergrid1" class="sq-grid"></div>
</div>
</body>
</html>